package com.coin.exchanges.adapter;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.coin.exchanges.R;
import com.coin.exchanges.model.MarketBean;
import com.coin.exchanges.model.okex.response.FuturesInstrumentsTickerList;
import com.coin.exchanges.model.okex.vo.RankItemVO;
import com.coin.exchanges.utils.AppUtils;

import java.util.List;

public class NewMarketAdapter extends BaseQuickAdapter<RankItemVO, BaseViewHolder> {
    public NewMarketAdapter(int layoutResId, @Nullable List<RankItemVO> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, RankItemVO item) {
        int drawable;
        switch (item.getNum()) {
            case 1:
                drawable = R.drawable.shape_rank_one_bg;
                break;
            case 2:
                drawable = R.drawable.shape_rank_two_bg;
                break;
            case 3:
                drawable = R.drawable.shape_rank_three_bg;
                break;
            default:
                drawable = R.drawable.shape_rank_other_bg;
                break;
        }
        View view = helper.getView(R.id.tv_rank_num);
        view.setBackground(ContextCompat.getDrawable(mContext, drawable));

        View tvRange = helper.getView(R.id.tv_range);
        if (item.isIncrease()) {
            tvRange.setBackground(AppUtils.getIncreaseBg());
        } else {
            tvRange.setBackground(AppUtils.getDecreaseBg());
        }
        ImageView ivIcon = helper.getView(R.id.iv_icon);
        Integer iconRes = AppUtils.ICON_MAP.get(item.getName());
        if (iconRes != null) {
            ivIcon.setImageDrawable(
                    ContextCompat.getDrawable(mContext, iconRes));
        }
        helper.setText(R.id.tv_name, item.getName())
                .setText(R.id.tv_rank_num, item.getNum() + "")
//                .setText(R.id.tv_name_des, item.getNameDes())
                .setText(R.id.tv_volume, item.getVolume())
                .setText(R.id.tv_value, item.getValue())
                .setText(R.id.tv_range, item.getRangeString())
        ;
    }

}
